<?php

/**
 * This class handles the template system
 * 
 * @author johan <info@johandahlberg.com>
 */
class Template {
	/**
	 * @the registry
	 * @access private
	 */
	private $registry;
	
	/**
	 * @Variables array
	 * @access private
	 */
	private $vars = array();
	
	/**
	 * @constructor
	 *
	 * @access public
	 * @return void
	 */
	function __construct($registry) {
		$this->registry = $registry;
	}
	
	
	 /**
	  * @set undefined vars
	  *
	  * @param string $index
	  * @param mixed $value
	  * @return void
	  */
	 public function __set($index, $value) {
	 	$this->vars[$index] = $value;
	 }
	
	
	/**
	 * Show view.
	 * 
	 * @param unknown_type $name
	 * @throws Exception
	 * @return boolean
	 */
	function show($name) {
		/**
		 * Fetch template from registry to get the templatefolder
		 */
		$path = __APP_PATH . '/views' . '/' . 'default/' . $name . '.php';
		$templatepath = __APP_PATH . '/templates' . '/' . 'default';
	
        if (file_exists($path) == false) {
			throw new Exception('Template not found in '. $path);
            return false;
        }

        // Load variables
        foreach ($this->vars as $key => $value) {
            $$key = $value;
        }

        include($templatepath . '/' . 'index.php');
        include ($path);
        include($templatepath . '/' . 'index2.php');
	}
}

?>